import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.tree.*;
import javax.swing.border.*;
import java.rmi.*;

public class Vote extends JInternalFrame implements ClientInterface
{
	public JPanel pan = new JPanel();
	public String rabio = "";
	public Vote()
	{
		super("Yes/No Vote Client",false,true,false,false);
		this.setBounds(60,30,600,450);
		setVisible(true);
		
		Container c = getContentPane();
		c.setLayout(null);
	
		lab25.setBounds(50,20,200,20);	
		lab25.setFont(new Font("Verdana",Font.PLAIN,14));
		c.add(lab25);
		taf10.setBounds(50,45,180,20);
		c.add(taf10);
		bt7.setBounds(280,38,90,35);
		c.add(bt7);
		pan.setLayout(null);
		pan.setBorder(new LineBorder(Color.red,2));
		pan.setBackground(Color.gray);
		pan.setBounds(50,80,490,310);
		c.add(pan);
		
		lab27.setBounds(50,15,200,20);
		lab27.setFont(new Font("Verdana",Font.PLAIN,14));
		pan.add(lab27);
		jsp6.setBounds(50,45,390,60);
		jsp6.setBorder(new LineBorder(Color.white,2));
		txa6.setFont(new Font("Verdana",Font.PLAIN,14));
		pan.add(jsp6);
		
		yesbutt.setBounds(200,120,90,35);
		yesbutt.setFont(new Font("Verdana",Font.BOLD,18));
		yesbutt.setBackground(Color.gray);
		pan.add(yesbutt);
		nobutt.setBounds(200,160,90,35);
		nobutt.setFont(new Font("Verdana",Font.BOLD,18));
		nobutt.setBackground(Color.gray);
		pan.add(nobutt);
		btyn.add(yesbutt);
		btyn.add(nobutt);
		
		RadioButtonHandler handler = new RadioButtonHandler();
		yesbutt.addItemListener(handler);
		nobutt.addItemListener(handler);
		
		
		bt12.setBounds(330,230,110,28);
		bt12.setFont(new Font("Verdana",Font.PLAIN,13));
		bt12.setBorder(new LineBorder(Color.white,1));
		pan.add(bt12);
		
		pan.setVisible(false);
		bt7.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent e) {
        		if(taf10.getText().equals(""))
        		JOptionPane.showMessageDialog(null,"Please Enter your Voter_ID","ERROR",JOptionPane.ERROR_MESSAGE);
        		else
        		{
        		pan.setVisible(true);
        		try {
        			
        		String ur = "rmi://"+clientconf.getText()+"/MainServer";
			MainServerInterface msin = (MainServerInterface)Naming.lookup(ur);
			
			String ra1 = msin.VoteYesNoQuestion(taf10.getText());
			txa6.setText(ra1);
			}
			catch(Exception ex)
			{
				JOptionPane.showMessageDialog(null,"Internal IIOP Error....\nContact to the Administrator..","Error",JOptionPane.ERROR_MESSAGE);
			}
			
		
        		}
        	}
        }
        );
		bt12.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				if(yesbutt.isSelected() == false && nobutt.isSelected() == false)
				{
				JOptionPane.showMessageDialog(null,"Please cut your vote","Information",JOptionPane.ERROR_MESSAGE);
				return;
				}
				else {
				if(yesbutt.isSelected() == true && nobutt.isSelected() == false)
				rabio = "Yes";
				if(yesbutt.isSelected() == false && nobutt.isSelected() == true)
				rabio = "No";
				
				try {
        			
        			String ur = "rmi://"+clientconf.getText()+"/MainServer";
				MainServerInterface msin = (MainServerInterface)Naming.lookup(ur);
			
				String ra = msin.voteYesNoAnswer(rabio);
				
			}
			catch(Exception ex)
			{
				JOptionPane.showMessageDialog(null,"Internal IIOP Error....\nContact to the Administrator..","Error",JOptionPane.ERROR_MESSAGE);
			}
			}
			}					
		}
		);
		
		try
		{
			UIManager.setLookAndFeel(looks[1].getClassName());
			SwingUtilities.updateComponentTreeUI(this);
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
		}
	}
	private class RadioButtonHandler implements ItemListener {
		public void itemStateChanged(ItemEvent ev) {
			if(ev.getSource() == yesbutt )
			{
			 
							
			}
			
			if(ev.getSource() == nobutt )
			{
			 						
			}
			
		}
		
		
		
		
	}
}
